package com.news.gpb.dao;

import com.news.gpb.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentDao {

    @Insert("insert into comments (user_id,news_id,comment_content) values(#{comment.user_id},#{comment.news_id},#{comment.comment_content})")
    @Options(useGeneratedKeys = true,keyProperty = "comment.comment_id",keyColumn = "comment_id")
    Integer insertComment(@Param("comment") Comment comment);

    @Select("select * from comments where news_id=#{comment.news_id} order by comment_date desc")
    List<Comment> getComment(@Param("comment") Comment comment);
}
